package com.platform.usercenter.domain.vo;

import cn.hutool.core.collection.CollectionUtil;
import com.platform.common.core.web.domain.BaseEntity;
import com.platform.usercenter.service.TreeAdapter;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 组织部门对象 sys_organization_dept
 *
 * @author platform
 * @date 2024-10-24
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class SysOrganizationDeptVO extends BaseEntity implements TreeAdapter {

    /**
     * 部门id
     */
    private Long deptId;
    /**
     * 父部门id
     */
    private Long parentId;
    /**
     * 部门名称
     */
    private String deptName;

    /**
     * 组织部门标识 (组织id_部门id)
     */
    private String orgDept;

    /**
     * 子部门列表
     */
    private List<SysOrganizationDeptVO> children = new ArrayList<>();

    @Override
    public Long getTreeCurrentId() {
        return deptId;
    }

    @Override
    public Long getTreeParentId() {
        return parentId;
    }

    @Override
    public <T> void setTreeChildren(List<TreeAdapter> list, Class<T> clazz) {
        if (this.getClass().isAssignableFrom(clazz) && CollectionUtil.isNotEmpty(list)) {
            List<SysOrganizationDeptVO> collect = list.stream().map(SysOrganizationDeptVO.class::cast).collect(Collectors.toList());
            this.setChildren(collect);
        }
    }


}
